package be.fedict.eid.diagnostics.system;

import java.util.ArrayList;
import java.util.List;

import javax.smartcardio.CardException;
import javax.smartcardio.CardTerminal;
import javax.smartcardio.CardTerminals;
import javax.smartcardio.TerminalFactory;


public class JavaPCSCManager implements PCSCManager {

	private final TerminalFactory terminalFactory;

	public JavaPCSCManager() {
		this.terminalFactory = TerminalFactory.getDefault();
	}
	
	public List<CardTerminal> readerList() {
		List<CardTerminal> readerList = new ArrayList<CardTerminal>();
		CardTerminals cardTerminals = terminalFactory.terminals();
		List<CardTerminal> cardTerminalList;
		
		try {
			cardTerminalList = cardTerminals.list();
		} catch (CardException e) {
			return readerList;
		}
		
		for (CardTerminal cardTerminal : cardTerminalList) {
			readerList.add(cardTerminal);
		}
		
		return readerList;
	}
	
}
